//
//  PersonEditView.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/11/28.
//

import Foundation
import UIKit

class PersonEditView: UIView {
    let nameItem = TextFieldEffect()
//    let jobNItem = TextFieldEffect()
    let companyItem = TextFieldEffect(withEnable: false)
    let phoneItem = TextFieldEffect()
    let cardItem = TextFieldEffect()
    let otherCardItem = TextFieldEffect()
    let cardPhotoItem = ImagePickerSingleEffect(withPlaceholder: "证件照片")
    let otherCardPhotoItem = ImagePickerSingleEffect(withPlaceholder: "保安证或其他证件照片")

    let submitBtn = UIButton.createPrimaryLarge("保存")

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .bg
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func updateUI(withParam param: UpOrSaveInfoParam) {
        nameItem.value = param.nickName
        companyItem.value = param.company
        phoneItem.value = param.phonenumber
        cardItem.value = param.idcard
        otherCardItem.value = param.baidcard
        cardPhotoItem.urlStr = param.zjzp
        otherCardPhotoItem.urlStr = param.bazfj
    }
    
    func setupUI() {
        addSubview(submitBtn)
        submitBtn.snp.makeConstraints { (make) -> Void in
            make.bottom.equalTo(self.safeAreaLayoutGuide.snp.bottom).offset(-10)
            make.height.equalTo(50)
            make.centerX.equalTo(self.snp.centerX)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        let scroll = UIScrollView()
        scroll.keyboardDismissMode = .interactive
        scroll.showsVerticalScrollIndicator = false
        addSubview(scroll)
        scroll.snp.makeConstraints { (make) -> Void in
            make.top.equalToSuperview()
            make.centerX.equalToSuperview()
            make.width.equalTo(ScreenWidth)
            make.bottom.equalTo(submitBtn.snp.top).offset(-10)
        }
        
        nameItem.placeholder = "姓名"
        scroll.addSubview(nameItem)
        nameItem.snp.makeConstraints { (make) -> Void in
            make.top.equalToSuperview().offset(10)
            make.centerX.equalToSuperview()
            make.height.equalTo(56)
            make.width.equalTo(ScreenWidth - 20)
        }
        
//        jobNItem.placeholder = "工号"
//        scroll.addSubview(jobNItem)
//        jobNItem.snp.makeConstraints { (make) -> Void in
//            make.top.equalTo(nameItem.snp.bottom).offset(10)
//            make.centerX.equalTo(self.snp.centerX)
//            make.height.equalTo(nameItem.snp.height)
//            make.width.equalTo(ScreenWidth - 20)
//        }
        
        companyItem.placeholder = "单位"
        scroll.addSubview(companyItem)
        companyItem.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(nameItem.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(nameItem.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        phoneItem.placeholder = "手机号"
        scroll.addSubview(phoneItem)
        phoneItem.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(companyItem.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(nameItem.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        cardItem.placeholder = "身份证号码"
        scroll.addSubview(cardItem)
        cardItem.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(phoneItem.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(nameItem.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        otherCardItem.placeholder = "其他证件号码"
        scroll.addSubview(otherCardItem)
        otherCardItem.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(cardItem.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(nameItem.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        scroll.addSubview(cardPhotoItem)
        cardPhotoItem.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(otherCardItem.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        scroll.addSubview(otherCardPhotoItem)
        otherCardPhotoItem.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(cardPhotoItem.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.width.equalTo(ScreenWidth - 20)
            make.bottom.equalToSuperview().offset(-10)
        }
    }
}
